package com.demo.com.stack_1;

import java.util.ArrayList;
import java.util.List;

public class Mystack {
    private List list = new ArrayList();

    synchronized public void push(){
        try {
            if(list.size() == 1){
                this.wait();
            }
            list.add("anyThiing string" + Math.random());
            this.notify();
            System.out.println("push= " + list.size());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    synchronized public String pop(){
        String returnValue = "";
        try {
            if(list.size() == 0){
                System.out.println("操作中的:" + Thread.currentThread().getName() + "线程呈 wait 状态");
                this.wait();
            }

            returnValue = "" + list.get(0);
            list.remove(0);
            this.notify();
            System.out.println("pop=" + list.size());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return returnValue;
    }


}
